home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 November / november_2001.iso / Browsers / Netscape 6.1 / browser.xpi / bin / chrome / toolkit.jar / content / global / globalOverlay.js < prev    next >
Encoding:
Text File  |  2001-07-10  |  4.1 KB  |  154 lines

  1. function goQuitApplication()
  2. {
  3.   var ObserverService = Components.classes["@mozilla.org/observer-service;1"].getService();
  4.   ObserverService = ObserverService.QueryInterface(Components.interfaces.nsIObserverService);
  5.   if (ObserverService)
  6.   {
  7.     try
  8.     {
  9.       ObserverService.Notify(null, "quit-application", null);
  10.     }
  11.     catch (ex)
  12.     {
  13.       // dump("no observer found \n");
  14.     }
  15.   }
  16.  
  17.   var windowManager = Components.classes['@mozilla.org/rdf/datasource;1?name=window-mediator'].getService();
  18.   var windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator);
  19.   var enumerator = windowManagerInterface.getEnumerator( null );
  20.   var appShell = Components.classes['@mozilla.org/appshell/appShellService;1'].getService();
  21.   appShell = appShell.QueryInterface( Components.interfaces.nsIAppShellService );
  22.  
  23.   var nativeAppSupport = null;
  24.   try {
  25.     nativeAppSupport = appShell.nativeAppSupport;
  26.   }
  27.   catch ( ex ) {
  28.   }
  29.  
  30.   while ( enumerator.hasMoreElements()  )
  31.   {
  32.     var  windowToClose = enumerator.getNext();
  33.     var domWindow = windowManagerInterface.convertISupportsToDOMWindow( windowToClose );
  34.     if (!("tryToClose" in domWindow))
  35.       domWindow.close();
  36.     else
  37.     {
  38.       if ( !domWindow.tryToClose() )
  39.         return false;
  40.     }
  41.   };
  42.   if (!nativeAppSupport || !nativeAppSupport.isServerMode)
  43.     appShell.Quit();
  44.   return true;
  45. }
  46.  
  47. //
  48. // Command Updater functions
  49. //
  50. function goUpdateCommand(command)
  51. {
  52.   try {
  53.     var controller = top.document.commandDispatcher.getControllerForCommand(command);
  54.  
  55.     var enabled = false;
  56.  
  57.     if ( controller )
  58.       enabled = controller.isCommandEnabled(command);
  59.  
  60.     goSetCommandEnabled(command, enabled);
  61.   }
  62.   catch (e) {
  63.     dump("An error occurred updating the "+command+" command\n");
  64.   }
  65. }
  66.  
  67. function goDoCommand(command)
  68. {
  69.   try {
  70.     var controller = top.document.commandDispatcher.getControllerForCommand(command);
  71.     if ( controller && controller.isCommandEnabled(command))
  72.       controller.doCommand(command);
  73.   }
  74.   catch (e) {
  75.     dump("An error occurred executing the "+command+" command\n");
  76.   }
  77. }
  78.  
  79.  
  80. function goSetCommandEnabled(id, enabled)
  81. {
  82.   var node = document.getElementById(id);
  83.  
  84.   if ( node )
  85.   {
  86.     if ( enabled )
  87.       node.removeAttribute("disabled");
  88.     else
  89.       node.setAttribute('disabled', 'true');
  90.   }
  91. }
  92.  
  93. function goSetMenuValue(command, labelAttribute)
  94. {
  95.   var commandNode = top.document.getElementById(command);
  96.   if ( commandNode )
  97.   {
  98.     var label = commandNode.getAttribute(labelAttribute);
  99.     if ( label )
  100.       commandNode.setAttribute('label', label);
  101.   }
  102. }
  103.  
  104. function goSetAccessKey(command, valueAttribute)
  105. {
  106.   var commandNode = top.document.getElementById(command);
  107.   if ( commandNode )
  108.   {
  109.     var value = commandNode.getAttribute(valueAttribute);
  110.     if ( value )
  111.       commandNode.setAttribute('accesskey', value);
  112.   }
  113. }
  114.  
  115. // this function is used to inform all the controllers attached to a node that an event has occurred
  116. // (e.g. the tree controllers need to be informed of blur events so that they can change some of the
  117. // menu items back to their default values)
  118. function goOnEvent(node, event)
  119. {
  120.   var numControllers = node.controllers.getControllerCount();
  121.   var controller;
  122.  
  123.   for ( var controllerIndex = 0; controllerIndex < numControllers; controllerIndex++ )
  124.   {
  125.     controller = node.controllers.getControllerAt(controllerIndex);
  126.     if ( controller )
  127.       controller.onEvent(event);
  128.   }
  129. }
  130.  
  131. function setTooltipText(aID, aTooltipText)
  132. {
  133.   var element = document.getElementById(aID);
  134.   if (element)
  135.     element.setAttribute("tooltiptext", aTooltipText);
  136. }
  137.  
  138. function FillInTooltip ( tipElement )
  139. {
  140.   var retVal = false;
  141.   var textNode = document.getElementById("TOOLTIP-tooltipText");
  142.   while (textNode.hasChildNodes())
  143.     textNode.removeChild(textNode.firstChild);
  144.   if (textNode) {
  145.     var tipText = tipElement.getAttribute("tooltiptext");
  146.     if (tipText) {
  147.       var node = document.createTextNode(tipText);
  148.       textNode.appendChild(node);
  149.       retVal = true;
  150.     }
  151.   }
  152.   return retVal;
  153. }
  154.